package com.example.gzysmartcity.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.blankj.utilcode.util.ThreadUtils;
import com.example.gzysmartcity.repository.model.Hrm;
import com.example.gzysmartcity.repository.remote.State;
import com.example.gzysmartcity.utils.NetworkUtil;

import java.util.ArrayList;
import java.util.List;

public class IdeaViewModel extends ViewModel {
    MutableLiveData<State> ideaLiveData=new MutableLiveData<>();
    List<Hrm.DataBean> hrmList;

    public void getHrmData(){
        ThreadUtils.executeByCached(new ThreadUtils.Task<Hrm>() {
            @Override
            public Hrm doInBackground() throws Throwable {
                return NetworkUtil.getInstance().get("Hrm/getAll?", null, Hrm.class, 0);
            }

            @Override
            public void onSuccess(Hrm result) {
                hrmList=result.getData();
                ideaLiveData.setValue(State.SUCCESS);
            }

            @Override
            public void onCancel() {

            }

            @Override
            public void onFail(Throwable t) {
                ideaLiveData.setValue(State.FAIL);
            }
        });
    }

    public List<String> getImageIdeaData(){
        List<String> str=new ArrayList<>();
        for (Hrm.DataBean hem:hrmList){
            str.add(hem.getHrmName());
        }
        str.add("更多人才市场待加入，敬请期待");
        return str;
    }

    public MutableLiveData<State> getIdeaLiveData() {
        return ideaLiveData;
    }

    public List<Hrm.DataBean> getHrmList() {
        return hrmList;
    }
}
